package com.theory.sms.util;

import lombok.Data;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Data
@Component
//注意prefix要写到最后一个 "." 符号之前
//调用setter为成员赋值
@ConfigurationProperties(prefix = "tencent.sms")
public class SmsProperties implements InitializingBean {
    private String secretId;
    private String secretKey;
    private String regionId;
    private String appId;
    private String templateId;
    private String signName;

    public static String SECRET_ID;
    public static String SECRET_KEY;
    public static String REGION_ID;
    public static String APP_ID;
    public static String TEMPLATE_ID;
    public static String SIGN_NAME;

    //当私有成员被赋值后，此方法自动被调用，从而初始化常量
    @Override
    public void afterPropertiesSet() throws Exception {
        SECRET_ID = secretId;
        SECRET_KEY = secretKey;
        REGION_ID = regionId;
        APP_ID = appId;
        TEMPLATE_ID = templateId;
        SIGN_NAME = signName;
    }

//    secret-id: AKIDVptfAWcQyFGzRcXBXdS0HGyQbV8VbQyF
//    secret-key: 2nHUQDm6D3cuvf8JDRP6VdU3LN8cplRq
//    region: ap-guangzhou
//    appId: 1400577822
//    template-id: 1143765
//    sign-name: 开拓猿
}
